<?php
namespace app\decorate\model;
use app\BaseModel;
use think\facade\Db;



class AdminPrice extends BaseModel
{
    //定义表名 价格表
    protected $name = 'longbing_card_decorate_price';

    protected $append=[
      'title'
    ];

    public function gettitleAttr($value,$data){
        return $data['min'].'-'.$data['max'].'万';
    }
    /**
     * @param $query
     * 查询范围
     */
    public function scopeStatus($query, $status){
        $query->where('status', '>', $status);
    }
    /**
     * @param $dis
     * @return array
     * @throws \think\exception\DbException
     * 价格列表
     */
    public function priceList($dis,$page = 10){
        $data = $this->where($dis)->status(-1)->order('sort desc')->paginate($page)->toArray();
        return $data;
    }

    /**
     * User: chenniang
     * Date: 2019-10-12 09:54
     * @param $dis
     * @return mixed
     * descption:查询价格
     */
    public function priceSelect($dis){
        $data = $this->where($dis)->status(-1)->order('sort desc')->select()->toArray();
        return $data;
    }

    /**
     * @param $data
     * @return int|string
     * 添加价格
     */
    public function priceAdd($data){
        $data['create_time'] = time();
        $data['update_time'] = time();
        $res = $this->insert($data);
        return $res;
    }
    /**
     * @param $dis
     * @param $data
     * @return AdminCate
     * 编辑价格
     */
    public function priceUpdate($dis,$data){
        $data['update_time'] = time();
        $res = $this->where($dis)->update($data);
        return $res;

    }
    /**
     * @param $dis
     * @return AdminCate
     * 价格详情
     */
    public function priceInfo($dis){
        $data = $this->where($dis)->status(-1)->find();
        return !empty($data)?$data->toArray():$data;
    }




}